package com.v1.video.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.v1.video.Constant;
import com.v1.video.R;
import com.v1.video.activity.PaikeVideoDetailActivity2;
import com.v1.video.activity.SharePlatformActionListener.SharePlatformCallback;
import com.v1.video.activity.ThemeDetailActivity;
import com.v1.video.activity.VideoPlayerVRActivity;
import com.v1.video.activity.WebViewActivity3;
import com.v1.video.db.dao.VideoTB;
import com.v1.video.db.service.OperateDB;
import com.v1.video.db.service.StatisticsDB;
import com.v1.video.domain.LoginInfo;
import com.v1.video.domain.ResultInfoEntity;
import com.v1.video.domain.ScenarioVideoInfo;
import com.v1.video.engine.NetEngine;
import com.v1.video.engine.RequestEngine;
import com.v1.video.fragment.ClassifyFragment;
import com.v1.video.httpmanager.ParamList;
import com.v1.video.httpmanager.ParamList.Parameter;
import com.v1.video.httpmanager.RequestManager;
import com.v1.video.httpmanager.RequestManager.OnResponseListener;
import com.v1.video.util.Helper;
import com.v1.video.util.Utility;
import com.v1.video.util.Utils;
import com.v1.video.view.VideoPlayerHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * 其他频道适配器
 * 
 * @author wangfang
 * 
 */
public class ClassifyAdapter2 extends BaseAdapter {

	private static final String READ_FLAG = "1";
	private LayoutInflater mLayoutInflater;
	private Context mContext;
	private List<VideoTB> mLstData;
	private String mType;
	private int mHeight;
	private int mIndex = -1;
	private int mCurIndex = -1;
	private Handler mHandler;
	private VideoPlayerHelper mPlayerHelper;// 视频播放辅助类
	private ClassifyFragment mParentFragment;
	private int mCurPosition = -1;
	private boolean mPlay = false;
	private String mCid;

	public ClassifyAdapter2(Context context) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mLstData = new ArrayList<VideoTB>();
		mHeight = Utils.computeImageHeight(mContext);
	}

	public String getCid() {
		return mCid;
	}

	public void setCid(String mCid) {
		this.mCid = mCid;
	}

	public List<VideoTB> getLst() {
		return mLstData;
	}

	public void setLstData(List<VideoTB> mLst) {
		if (mLst != null && mLst.size() > 0) {
			this.mLstData = mLst;
			this.notifyDataSetChanged();
		}
	}

	public void setAddLstData(List<VideoTB> mLst) {
		if (mLst != null && mLst.size() > 0) {
			this.mLstData.addAll(mLst);
			this.notifyDataSetChanged();
		}
	}

	public void setCurPosition(int mCurPosition) {
		this.mCurPosition = mCurPosition;
	}

	public int getIndex() {
		return mIndex;
	}

	public int getCurIndex() {
		return mCurIndex;
	}

	public void setIndex(int mIndex) {
		this.mIndex = mIndex;
	}

	public Handler getHandler() {
		return mHandler;
	}

	public void setHandler(Handler mHandler) {
		this.mHandler = mHandler;
	}

	public String getmType() {
		return mType;
	}

	public void setmType(String mType) {
		this.mType = mType;
	}

	public void setParentFragment(ClassifyFragment parentFragment) {
		this.mParentFragment = parentFragment;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mLstData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mLstData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder = null;
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.fragment_classify_item, null);
			holder = new Holder();
			holder.layItem = (RelativeLayout) convertView
					.findViewById(R.id.lay_item);
			holder.image = (ImageView) convertView.findViewById(R.id.iv_image);
			holder.time = (TextView) convertView.findViewById(R.id.tv_time);
			holder.title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.name = (TextView) convertView.findViewById(R.id.tv_name);
			holder.layBig = convertView.findViewById(R.id.lay_item_big);
			holder.image_big = (ImageView) convertView
					.findViewById(R.id.iv_image_big);
			holder.time_big = (TextView) convertView
					.findViewById(R.id.tv_time_big);
			holder.title_big = (TextView) convertView
					.findViewById(R.id.tv_title_big);
			holder.play = (TextView) convertView.findViewById(R.id.tv_play);
			holder.layImage = convertView.findViewById(R.id.lay_image);
			holder.layPlayer = convertView.findViewById(R.id.videoPlayLayout);
			holder.layPraise = convertView.findViewById(R.id.lay_praise);
			holder.layShare = convertView.findViewById(R.id.lay_share);
			holder.layPlay = convertView.findViewById(R.id.lay_play);
			holder.LayRefresh = convertView.findViewById(R.id.lay_item_refresh);
			holder.praise = (TextView) convertView.findViewById(R.id.tv_praise);
			holder.share = (TextView) convertView.findViewById(R.id.tv_share);
			holder.layAdv = convertView.findViewById(R.id.lay_item_adv);
			holder.image_adv = (ImageView) convertView
					.findViewById(R.id.iv_image_adv);
			holder.titleAdv = (TextView) convertView
					.findViewById(R.id.tv_title_adv);
			holder.cornerAdv = (TextView) convertView
					.findViewById(R.id.tv_corner_adv);
			holder.layTheme = convertView.findViewById(R.id.lay_item_theme);
			holder.image_theme = (ImageView) convertView
					.findViewById(R.id.iv_image_theme);
			holder.layAd = convertView.findViewById(R.id.lay_item_ad);
			holder.image_ad = (ImageView) convertView
					.findViewById(R.id.iv_image_ad);
			holder.layTools = convertView.findViewById(R.id.lay_tools);
			holder.iv_headpic = (ImageView) convertView.findViewById(R.id.iv_headpic);
			holder.user_name = (TextView) convertView.findViewById(R.id.user_name);
			holder.tv_share = (TextView) convertView.findViewById(R.id.tv_share);
			holder.ll_share = (LinearLayout) convertView.findViewById(R.id.ll_share);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		try {
			final VideoTB video = mLstData.get(position);
			if (!TextUtils.isEmpty(mType) && mType.equals("2")) {
				holder.layItem.setVisibility(View.GONE);
				if (!TextUtils.isEmpty(video.getAt())
						&& Constant.VIDEO_TYPE_7.equals(video.getAt())) {
					holder.layBig.setVisibility(View.GONE);
					holder.layAdv.setVisibility(View.GONE);
					holder.layAd.setVisibility(View.GONE);
					holder.layTheme.setVisibility(View.VISIBLE);
					if (TextUtils.isEmpty(video.getPic())) {
						holder.image_theme
								.setImageResource(R.drawable.common_place_holder_bg_16_10);
					} else {
						ImageLoader.getInstance()
								.displayImage(video.getPic(),
										holder.image_theme,
										Constant.VIDEO_10_16_OPTION);
					}

					if (mIndex != -1 && mIndex == position) {
						holder.LayRefresh.setVisibility(View.VISIBLE);
						holder.LayRefresh
								.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {
										// TODO Auto-generated method stub
										if (Helper.checkConnection(mContext)) {
											mHandler.sendEmptyMessage(Constant.CLASSIFY_REFRESH);
										} else {
											showToast();
										}
									}
								});
					} else {
						holder.LayRefresh.setVisibility(View.GONE);
					}

					holder.image_theme
							.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									// TODO Auto-generated method stub
									if (Helper.checkConnection(mContext)) {
										if (video != null) {
											transferThemeDetail(
													video.getTitle(),
													video.getTid(),
													video.getPic());
										}
									} else {
										showToast();
									}
								}
							});
				} else if (!TextUtils.isEmpty(video.getAt())
						&& Constant.VIDEO_TYPE_8.equals(video.getAt())) {
					holder.layBig.setVisibility(View.GONE);
					holder.layTheme.setVisibility(View.GONE);
					holder.layAd.setVisibility(View.GONE);
					holder.layAdv.setVisibility(View.VISIBLE);
					LayoutParams params = holder.image_adv.getLayoutParams();
					params.height = mHeight;
					holder.image_adv.setLayoutParams(params);
					if (TextUtils.isEmpty(video.getPic())) {
						holder.image_adv
								.setImageResource(R.drawable.common_place_holder_bg_16_10);
					} else {
						ImageLoader.getInstance().displayImage(video.getPic(),
								holder.image_adv, Constant.VIDEO_10_16_OPTION);
					}
					if(!TextUtils.isEmpty(video.getTitle())){
						holder.titleAdv.setText(video.getTitle());
					} else {
						holder.titleAdv.setText("");
					}
					if (!TextUtils.isEmpty(video.getMark())) {
						holder.cornerAdv.setText(video.getMark());
						holder.cornerAdv.setVisibility(View.VISIBLE);
					} else {
						holder.cornerAdv.setVisibility(View.GONE);
					}
					if (mIndex != -1 && mIndex == position) {
						holder.LayRefresh.setVisibility(View.VISIBLE);
						holder.LayRefresh
								.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {
										// TODO Auto-generated method stub
										if (Helper.checkConnection(mContext)) {
											mHandler.sendEmptyMessage(Constant.CLASSIFY_REFRESH);
										} else {
											showToast();
										}
									}
								});
					} else {
						holder.LayRefresh.setVisibility(View.GONE);
					}

					holder.image_adv.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (Helper.checkConnection(mContext)) {
								if (video != null
										&& !TextUtils.isEmpty(video.getAdURL())) {
									String url = video.getAdURL().replace(
											"{random}",
											Utils.getRandomString(10));
									transferWebView(video.getTitle(), url);
									RequestEngine request = new RequestEngine();
									request.sendADVLogToServer(mContext,
											Constant.STATE_ADV_CZBM_1 + "",
											Constant.STATE_ADV_CZSX_3 + "_"
													+ video.getTid(), ""
													+ Constant.STATE_ADV_CZJG_3);
									if (position == 1 || position == 5
											|| position == 8) {
										String adid = (position + 1) + "";
										new NetEngine().AdUpToServer(mContext,
												video.getAdid(), LoginInfo
														.getInstance()
														.getUserId(), adid,
												"2", mCid);
									}
								}
							} else {
								showToast();
							}
						}
					});
				} else if (!TextUtils.isEmpty(video.getAt())
						&& Constant.VIDEO_TYPE_0.equals(video.getAt())) {
					holder.layBig.setVisibility(View.GONE);
					holder.layAdv.setVisibility(View.GONE);
					holder.layTheme.setVisibility(View.GONE);
					holder.layAd.setVisibility(View.VISIBLE);
					LayoutParams params = holder.image_ad.getLayoutParams();
					params.height = mHeight;
					holder.image_ad.setLayoutParams(params);
					if (TextUtils.isEmpty(video.getPic())) {
						holder.image_ad
								.setImageResource(R.drawable.common_place_holder_bg_16_10);
					} else {
						ImageLoader.getInstance().displayImage(video.getPic(),
								holder.image_ad, Constant.VIDEO_10_16_OPTION);
					}
					if (mIndex != -1 && mIndex == position) {
						holder.LayRefresh.setVisibility(View.VISIBLE);
						holder.LayRefresh
								.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {
										// TODO Auto-generated method stub
										if (Helper.checkConnection(mContext)) {
											mHandler.sendEmptyMessage(Constant.CLASSIFY_REFRESH);
										} else {
											showToast();
										}
									}
								});
					} else {
						holder.LayRefresh.setVisibility(View.GONE);
					}

					holder.image_ad.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (Helper.checkConnection(mContext)) {
								if (Constant.VIDEO_TYPE_0.equals(video.getAt())) {

								}
							} else {
								showToast();
							}
						}
					});
				} else {
					holder.layBig.setVisibility(View.VISIBLE);
					holder.layAdv.setVisibility(View.GONE);
					holder.layTheme.setVisibility(View.GONE);
					holder.layAd.setVisibility(View.GONE);
					if (!TextUtils.isEmpty(video.getDuration())) {
						holder.time_big.setText(Utility.getDuration(video
								.getDuration()));
					} else {
						holder.time_big.setText("00:00");
					}
					if (!TextUtils.isEmpty(video.getTitle())) {
						holder.title_big.setText(video.getTitle());
					} else {
						holder.title_big.setText("");
					}
					if ("47".equals(mCid)) {
						holder.layTools.setVisibility(View.GONE);
						holder.time_big.setVisibility(View.GONE);
					} else {
						holder.layTools.setVisibility(View.VISIBLE);
						holder.time_big.setVisibility(View.VISIBLE);
//						if (!TextUtils.isEmpty(video.getPlayNum())) {
//							holder.play.setText(video.getPlayNum());
//						} else {
//							holder.play.setText("0");
//						}
//						if (!TextUtils.isEmpty(video.getLikeNum())) {
//							holder.praise.setText(video.getLikeNum());
//						} else {
//							holder.praise.setText("0");
//						}
//						if (!TextUtils.isEmpty(video.getShareNum())) {
//							holder.share.setText(video.getShareNum());
//						} else {
//							holder.share.setText("0");
//						}
					}
					LayoutParams params = holder.image_big.getLayoutParams();
					params.height = mHeight;
					holder.image_big.setLayoutParams(params);
					if (TextUtils.isEmpty(video.getPic())) {
						holder.image_big
								.setImageResource(R.drawable.common_place_holder_bg_16_10);
					} else {
						ImageLoader.getInstance().displayImage(video.getPic(),
								holder.image_big, Constant.VIDEO_10_16_OPTION);
					}
					LayoutParams playerParam = holder.layPlayer
							.getLayoutParams();
					playerParam.height = mHeight;
					holder.layPlayer.setLayoutParams(playerParam);
					
					ImageLoader.getInstance().displayImage(video.getHeadpic(),
							holder.iv_headpic, Constant.IMAGE_OPTIONS_FOR_USER_OTHER, new SimpleImageLoadingListener() {

						public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
							if(loadedImage!=null){
								ImageView iv = (ImageView) view;
								iv.setImageBitmap(Utils.toRoundBitmap(loadedImage));
							}
						}

					});
					
					if(!TextUtils.isEmpty(video.getName())){
						holder.user_name.setText(video.getName());
					}else{
						holder.user_name.setText("");
					}
					
					if(!TextUtils.isEmpty(video.getShareNum())){
						holder.tv_share.setText(video.getShareNum()+"次分享");
					}else{
						holder.tv_share.setText("0次分享");
					}
					
					if (mIndex != -1 && mIndex == position) {
						holder.LayRefresh.setVisibility(View.VISIBLE);
						holder.LayRefresh
								.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {
										// TODO Auto-generated method stub
										if (Helper.checkConnection(mContext)) {
											mHandler.sendEmptyMessage(Constant.CLASSIFY_REFRESH);
										} else {
											showToast();
										}
									}
								});
					} else {
						holder.LayRefresh.setVisibility(View.GONE);
					}
					if (mCurIndex != -1 && mCurIndex == position) {
						holder.layPlayer.setVisibility(View.VISIBLE);
						holder.layImage.setVisibility(View.GONE);
						mPlayerHelper = new VideoPlayerHelper(mContext,
								holder.layPlayer);
						mPlayerHelper.setParentFragment(mParentFragment);
						mPlayerHelper.setTitle(video.getTitle());
						mPlayerHelper.setVideoURI(video.getVideoUrl());
						mPlayerHelper.setVid(video.getVid());
						mPlayerHelper.start();
						mPlay = true;
					} else {
						holder.layImage.setVisibility(View.VISIBLE);
						holder.layPlayer.setVisibility(View.GONE);

					}

					holder.layImage.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (Helper.checkConnection(mContext)) {
								if (video != null) {
									if (!TextUtils.isEmpty(video.getAt())
											&& !Constant.VIDEO_TYPE_1
													.equals(video.getAt())) {
										transferActivity(video, position);
									} else {
										if (!TextUtils.isEmpty(video
												.getVideoUrl())) {
											if (mPlayerHelper != null
													&& mCurIndex != position) {
												mPlayerHelper.release();
												mPlayerHelper = null;
											}
											mCurIndex = position;
											requestPlayVideo(video);
											ClassifyAdapter2.this
													.notifyDataSetChanged();
										}
									}
								}
							} else {
								showToast();
							}
						}
					});
//					holder.layPraise.setOnClickListener(new OnClickListener() {
//
//						@Override
//						public void onClick(View v) {
//							// TODO Auto-generated method stub
//							if (Helper.checkConnection(mContext)) {
//								if (video != null) {
//									requestPraise(video);
//								}
//							} else {
//								showToast();
//							}
//						}
//					});

					holder.ll_share.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (Helper.checkConnection(mContext)) {
								if (video != null) {
									requestShareVideo(video);
								}
							} else {
								showToast();
							}
						}
					});
					
					holder.title_big.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (Helper.checkConnection(mContext)) {
								if (video != null) {
									transferActivity(video, position);
								}
							} else {
								showToast();
							}
						}
					});

					holder.layTools.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (Helper.checkConnection(mContext)) {
								if (video != null) {
									transferActivity(video, position);
								}
							} else {
								showToast();
							}
						}
					});
				}
			} else {
				holder.layItem.setVisibility(View.VISIBLE);
				holder.layBig.setVisibility(View.GONE);
				holder.LayRefresh.setVisibility(View.GONE);
				if (!TextUtils.isEmpty(video.getDuration())) {
					holder.time
							.setText(Utility.getDuration(video.getDuration()));
				} else {
					holder.time.setText("00:00");
				}
				if (!TextUtils.isEmpty(video.getTitle())) {
					holder.title.setText(video.getTitle());
				} else {
					holder.title.setText("");
				}
				if (!TextUtils.isEmpty(video.getName())) {
					holder.name.setText("来自:" + video.getName());
				} else {
					holder.name.setText("");
				}
				if (TextUtils.isEmpty(video.getPic())) {
					holder.image
							.setImageResource(R.drawable.common_place_holder_bg_16_10);
				} else {
					ImageLoader.getInstance().displayImage(video.getPic(),
							holder.image, Constant.VIDEO_10_16_OPTION);
				}

				holder.layItem.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (Helper.checkConnection(mContext)) {
							if (video != null) {
								transferActivity(video, position);
							}
						} else {
							showToast();
						}
					}
				});
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return convertView;
	}

	/**
	 * 请求点赞视频
	 * 
	 * @param video
	 */
	private void requestPraise(final VideoTB video) {
		String uid = "";
		if (LoginInfo.getInstance().isLogin()) {
			uid = LoginInfo.getInstance().getUserId();
		}
		String url = String.format(Constant.HOME_CLASSIFY_VIDEO_PRAISE,
				video.getVid(), uid, Constant.PRODUCT_CODE,
				Constant.PRODUCT_VERSION, Constant.DEVICEID);
		RequestManager.getInstance().getRequest(mContext, url,
				ResultInfoEntity.class, new OnResponseListener() {

					@Override
					public void onSuccess(Object object, int code,
							String message, String keyId) {
						// TODO Auto-generated method
						// stub
						if (object != null) {
							ResultInfoEntity entity = (ResultInfoEntity) object;
							if (entity != null
									&& entity.getBody() != null
									&& entity.getBody().getResult() != null
									&& !TextUtils.isEmpty(entity.getBody()
											.getResult().getCode())) {
								if (Constant.RESULT_CODE_SUCCESS.equals(entity
										.getBody().getResult().getCode())) {
									int praiseNum = 1;
									if (!TextUtils.isEmpty(video.getLikeNum())) {
										praiseNum += Integer.parseInt(video
												.getLikeNum());
									}
									video.setLikeNum(praiseNum + "");
									ClassifyAdapter2.this.notifyDataSetChanged();
									showPraiseToast();
								}
							}
						}
					}

					@Override
					public void onFailure(int code, String message) {
						// TODO Auto-generated method
						// stub
						showToast(message);
					}
				});
	}

	/**
	 * 请求分享视频
	 * 
	 * @param video
	 */
	private void requestShareVideo(final VideoTB video) {
		if (mParentFragment != null) {
			mParentFragment.showShareDialog(video, new SharePlatformCallback() {

				@Override
				public void success() {
					// TODO Auto-generated
					// method stub
					String uid = "";
					if (LoginInfo.getInstance().isLogin()) {
						uid = LoginInfo.getInstance().getUserId();
					}
					String url = String.format(
							Constant.HOME_CLASSIFY_VIDEO_SHARE,
							Constant.PRODUCT_CODE, Constant.PRODUCT_VERSION,
							Constant.DEVICEID);
					ParamList params = new ParamList();
					params.add(new Parameter("userId", uid));
					params.add(new Parameter("videoId", video.getVid()));
					RequestManager.getInstance().postRequest(mContext, url,
							params, ResultInfoEntity.class,
							new OnResponseListener() {

								@Override
								public void onSuccess(Object object, int code,
										String message, String keyId) {
									// TODO Auto-generated method stub
									if (object != null) {
										ResultInfoEntity entity = (ResultInfoEntity) object;
										if (entity != null
												&& entity.getBody() != null
												&& entity.getBody().getResult() != null
												&& !TextUtils.isEmpty(entity
														.getBody().getResult()
														.getCode())) {
											if (Constant.RESULT_CODE_SUCCESS
													.equals(entity.getBody()
															.getResult()
															.getCode())) {
												int shareNum = 1;
												if (!TextUtils.isEmpty(video
														.getLikeNum())) {
													shareNum += Integer.parseInt(video
															.getShareNum());
												}
												video.setShareNum(shareNum + "");
												ClassifyAdapter2.this
														.notifyDataSetChanged();
											}
										}
									}
								}

								@Override
								public void onFailure(int code, String message) {
									// TODO Auto-generated method stub
									showToast(message);
								}

							});
				}
			});
		}
	}

	/**
	 * 请求播放次数
	 * 
	 * @param video
	 */
	private void requestPlayVideo(final VideoTB video) {
		String uid = "";
		if (LoginInfo.getInstance().isLogin()) {
			uid = LoginInfo.getInstance().getUserId();
		}
		String url = String.format(Constant.HOME_CLASSIFY_VIDEO_PLAY,
				video.getVid(), uid, Constant.PRODUCT_CODE,
				Constant.PRODUCT_VERSION, Constant.DEVICEID);
		RequestManager.getInstance().getRequest(mContext, url);
	}

	public void resumePlayer() {
		if (mPlayerHelper != null) {
			mPlayerHelper.resetStart();
			mPlayerHelper.seekTo(mCurPosition);
		}
	}

	public void releasePlayer() {
		if (mPlayerHelper != null) {
			mPlayerHelper.release();
			mPlayerHelper = null;
		}
		mPlay = false;
		mCurIndex = -1;
		mCurPosition = -1;
		this.notifyDataSetChanged();
	}

	public void pausePlayer() {
		if (mPlayerHelper != null) {
			mCurPosition = mPlayerHelper.getCurrentPosition();
			mPlayerHelper.pause();
		}
	}

	/**
	 * 显示Toast信息
	 * 
	 */
	private void showToast() {
		Toast.makeText(mContext,
				mContext.getResources().getString(R.string.net_no_notclick),
				Toast.LENGTH_SHORT).show();
	}

	/**
	 * 显示Toast信息
	 * 
	 */
	private void showToast(String message) {
		Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
	}

	/**
	 * 点赞显示
	 */
	private void showPraiseToast() {
		Toast toast = Toast.makeText(mContext, "点赞成功", Toast.LENGTH_SHORT);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.show();
	}

	private void transferActivity(VideoTB video, int pos) {
		if (!TextUtils.isEmpty(video.getAt())) {
			if (Constant.VIDEO_TYPE_4.equals(video.getAt())) {
				transferWebView(video.getTitle(), video.getVideoUrl());
			} else if (Constant.VIDEO_TYPE_6.equals(video.getAt())) {
				if (video.getVideoUrl() != null
						&& video.getVideoUrl().length() >= 6) {
					// transferVR(video.getVideoUrl());
					transferVR(pos);
				} else {
					transferVideoDetail(video);
				}
			} else if (Constant.VIDEO_TYPE_7.equals(video.getAt())) {
				transferThemeDetail(video.getTitle(), video.getTid(),
						video.getPic());
			} else {
				transferVideoDetail(video);
			}
		} else {
			transferVideoDetail(video);
		}
	}

	/**
	 * 跳转视频详情
	 * 
	 * @param vid
	 */
	private void transferVideoDetail(VideoTB video) {
		if (TextUtils.isEmpty(video.getFlag())
				|| !READ_FLAG.equals(video.getFlag())) {
			try {
				long result = OperateDB.getInstance().insert(video.getVid(),
						video.getCid());
				if (result > 0) {
					video.setFlag(READ_FLAG);
					StatisticsDB.getInstance().insertOrUpdate(video.getCid());
				}
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
		requestPlayVideo(video);
		ScenarioVideoInfo videoInfo = new ScenarioVideoInfo(video.getVid());
		if (videoInfo != null) {
			Intent intent = new Intent();
			intent.setClass(mContext, PaikeVideoDetailActivity2.class);
			intent.putExtra("videoInfo", videoInfo);
			intent.putExtra("name", video.getName());
			intent.putExtra("source", Constant.ADV_SOURCE_CLASSIFY);
			mContext.startActivity(intent);
		}
	}

	/**
	 * 跳转网页
	 * 
	 * @param title
	 * @param url
	 */
	private void transferWebView(String title, String url) {
		Intent intent = new Intent();
		intent.setClass(mContext, WebViewActivity3.class);
		intent.putExtra("adLink", url);
		intent.putExtra(WebViewActivity3.FLAG_TITLE, title);
		mContext.startActivity(intent);
	}

	/**
	 * 跳转VR
	 * 
	 * @param url
	 */
	private void transferVR(String url) {
		Intent intent = new Intent();
		intent.setClass(mContext, VideoPlayerVRActivity.class);
		intent.putExtra("videourl", url);
		mContext.startActivity(intent);
	}

	/**
	 * 跳转VR
	 * 
	 * @param url
	 */
	private void transferVR(int pos) {
		Intent intent = new Intent();
		intent.setClass(mContext, VideoPlayerVRActivity.class);
		ArrayList<String> listUrl = new ArrayList<String>();
		for (int i = 0; i < mLstData.size(); i++) {
			listUrl.add(mLstData.get(i).getVideoUrl());
		}
		// intent.putExtra("videourl", url);
		intent.putStringArrayListExtra("videourl", listUrl);
		intent.putExtra("pos", pos);
		mContext.startActivity(intent);
	}

	/**
	 * 跳转主题详情
	 * 
	 * @param title
	 * @param tid
	 * @param imgUrl
	 */
	private void transferThemeDetail(String title, String tid, String imgUrl) {
		Intent intent = new Intent();
		intent.setClass(mContext, ThemeDetailActivity.class);
		intent.putExtra("title", title);
		intent.putExtra("themdId", tid);
		intent.putExtra("themeImg", imgUrl);
		mContext.startActivity(intent);
	}

	private class Holder {
		public RelativeLayout layItem;
		public ImageView image;
		public TextView time;
		public TextView title;
		public TextView name;
		public View layBig;
		public ImageView image_big;
		public TextView time_big;
		public TextView title_big;
		public TextView play;
		public View layImage;
		public View layPlayer;
		public View layPraise;
		public View layShare;
		public View layPlay;
		public View LayRefresh;
		public TextView praise;
		public TextView share;
		public View layAdv;
		public ImageView image_adv;
		public View layTheme;
		public ImageView image_theme;
		public TextView titleAdv;
		public TextView cornerAdv;
		public View layAd;
		public ImageView image_ad;
		public View layTools;
		public ImageView iv_headpic;
		public TextView user_name,tv_share;
		public LinearLayout ll_share;
	}

}
